package com.iwhalecloud.bss.kite.cucc.web.service.accept.handler.attr;

import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalKeyConsts;
import com.iwhalecloud.bss.kite.dataservice.cache.ProductCache;
import com.iwhalecloud.bss.kite.dataservice.entity.spec.Product;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.manager.inst.KiteProdInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.attr.handler.AbstractAttrHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

@Service
public class TransferPlanBookPeriodHandler extends AbstractAttrHandler<KiteInst, AttrData> {

    @Autowired
    private IQuerySceneInstService querySceneInstService;

    @Override
    public void after(KiteAttr attr, KiteInst inst, AttrData data) {
        super.after(attr, inst, data);

        List<KiteProdInst> kiteProdInstList = querySceneInstService.listProdInsts(data.getSceneInstId());
        kiteProdInstList.forEach(KiteProdInst -> {
            Product product = ProductCache.get(KiteProdInst.getProdId());
            if (KiteStringUtils.isEqual(KeyConsts.PROD_FUNC_TYPE_101, product.getProdFuncType())) {

                KiteAttr kiteAttr = KiteProdInst.getAttrMap().get(LocalKeyConsts.MAIN_BILLING_MODE);
                if (!Objects.isNull(kiteAttr)) {
                    if (KiteStringUtils.isEqual(LocalKeyConsts.BILLING_CHARTER_MODE, kiteAttr.getValue())) {
                        attr.setShowType(KeyConsts.PROD_ATTR_SHOW_TYPE_E);
                    }
                    else {
                        attr.setShowType(KeyConsts.PROD_ATTR_SHOW_TYPE_D);
                    }
                }
            }
        });
    }
}
